import { reqGoodsInfo,reqAddOrupdateShopCart } from "@/api";
//封装游客身份模块uuid
import {getUUID} from '@/utils/uuid_token'

const state={
  goodInfo:{},
  uuid_token:getUUID()
};

const actions={
  //获取产品信息的actions
  async getGoodsInfo(context,skuId){
    let result= await reqGoodsInfo(skuId);

     if(result.code==200){
      
      context.commit('GETGOODSINFO',result.data)
        
     }
  },
  //将产品添加到购物车中
  async addOrUpdateShopCart(context,{skuId,skuNum}){
      
      
    try {
       await reqAddOrupdateShopCart(skuId,skuNum)
    } catch (error) {
      return Promise.reject(new Error('faile'))
    }
       
     
    }
};

const mutations={
  GETGOODSINFO(state,goodInfo){
     state.goodInfo=goodInfo
     
  },

};

const getters={
  categoryView(state){
    return state.goodInfo.categoryView|| {};
  },
  skuInfo(state){
    return state.goodInfo.skuInfo || {}
  },

  spuSaleAttrList(state){
    return state.goodInfo.spuSaleAttrList || []
  }
};

export default {
  state,
  actions,
  mutations,
  getters
}